package com.mercator.client.main.view;

import java.util.Collection;
import java.util.Set;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SplitLayoutPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class RootView extends Composite{
	private  Frame genesetList = new Frame();
	public  DockLayoutPanel dockPanel = new DockLayoutPanel(Unit.PX);
	private  Image jaccardImg = new Image((String) null);
	private  DockLayoutPanel dockPanel_1 = new DockLayoutPanel(Unit.PX);
	private  ListBox mapSelection = new ListBox();
	private  SimplePanel mapDisplay = new SimplePanel();
	private  ListBox geneList = new ListBox();
	private Button drawBtn = new Button("Draw");
	private SplitLayoutPanel splitLayoutPanel;
	 
	 public Image getJaccardImg() {
		return jaccardImg;
	}
	 
	 public Button getDrawBtn(){
		 return drawBtn;
	 }

	public ListBox getGeneList() {
		return geneList;
	}

	public Frame getGenesetList() {
		return genesetList;
	}

	public SimplePanel getMapDisplay() {
		return mapDisplay;
	}

	public ListBox getMapSelection() {
		return mapSelection;
	}
	
	public String getSelectedMap(){
		Window.alert(mapSelection.getValue(mapSelection.getSelectedIndex()) + " selected");
		return mapSelection.getValue(mapSelection.getSelectedIndex());
	}
	
	public void setBody(Widget w){
		mapDisplay.setWidget(w);
		w.setHeight(mapDisplay.getOffsetHeight() + "px");
		w.setWidth(mapDisplay.getOffsetWidth() + "px");
	}
	
	
	@Inject
	public RootView () {
		Window.alert( "Message!" );
		SplitLayoutPanel splitLayoutPanel = new SplitLayoutPanel();
		//jaccardImg.setUrl("jaccard.png");
	 	geneList.setVisibleItemCount(5);
	 //	mapSelection.addItem("GeneSet Map");
	 // mapSelection.addItem("Phenome Map");
	 	jaccardImg.setUrl("jaccard.png");
		jaccardImg.setSize("100%","100%");
		dockPanel.addEast(jaccardImg, jaccardImg.getWidth());
		dockPanel.add(geneList);

	 	FlowPanel fp = new FlowPanel();
	 	ScrollPanel sp = new ScrollPanel();
	 	fp.add(mapSelection);
	 	fp.add(drawBtn);
	 	dockPanel_1.addNorth(fp,20);
	 	mapSelection.setWidth("95%");
	 	drawBtn.setWidth("5%");
	 	sp.add(mapDisplay);
	 	dockPanel_1.add(sp);
	 	dockPanel.setSize("100%", "100%");
		
	 	initWidget(splitLayoutPanel);

		splitLayoutPanel.setHeight(RootLayoutPanel.get().getOffsetHeight() + "px");
		splitLayoutPanel.addSouth(dockPanel,jaccardImg.getHeight() );
		FlowPanel fp2 = new FlowPanel();
		fp2.add(genesetList);
		genesetList.setSize("100%", "100%");
		splitLayoutPanel.addEast(fp2, jaccardImg.getWidth());
	 	splitLayoutPanel.add(dockPanel_1);
	 }

	
	public void setImage(String url){
		
	 
		//dockPanel.addEast(jaccardImg, jaccardImg.getHeight());
	 	//splitLayoutPanel.insertSouth(dockPanel,jaccardImg.getHeight(),dockPanel );
		//splitLayoutPanel.insertEast(genesetList, jaccardImg.getWidth(),genesetList);
		
	}
	
	public void setGeneSetPage(String url){
		genesetList.setUrl(url);
	}
	
	public void setGeneSetList(Set<?> g){
		for(Object o : g)
			geneList.addItem(o.toString());
	}
	 
	 
}



